home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / php / pear / XML / Transformer / Namespace.php < prev   
PHP Script  |  2004-03-24  |  5KB  |  204 lines

  1. <?php
  2. //
  3. // +---------------------------------------------------------------------------+
  4. // | PEAR :: XML :: Transformer                                                |
  5. // +---------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2004 Sebastian Bergmann <sb@sebastian-bergmann.de> and |
  7. // |                         Kristian K÷hntopp <kris@koehntopp.de>.            |
  8. // +---------------------------------------------------------------------------+
  9. // | This source file is subject to version 3.00 of the PHP License,           |
  10. // | that is available at http://www.php.net/license/3_0.txt.                  |
  11. // | If you did not receive a copy of the PHP license and are unable to        |
  12. // | obtain it through the world-wide-web, please send a note to               |
  13. // | license@php.net so we can mail you a copy immediately.                    |
  14. // +---------------------------------------------------------------------------+
  15. //
  16. // $Id: Namespace.php,v 1.23 2004/01/01 10:31:53 sebastian Exp $
  17. //
  18.  
  19. require_once 'XML/Util.php';
  20.  
  21. /**
  22. * Convenience Base Class for Namespace Transformers.
  23. *
  24. * Example
  25. *
  26. *   <?php
  27. *   require_once 'XML/Transformer.php';
  28. *   require_once 'XML/Transformer/Namespace.php';
  29. *
  30. *   class Image extends XML_Transformer_Namespace {
  31. *       var $imageAttributes = array();
  32. *
  33. *       function truePath($path) {
  34. *           if (php_sapi_name() == 'apache') {
  35. *               $r    = apache_lookup_uri($path);
  36. *               $path = $r->filename;
  37. *           } else {
  38. *               $path = $_SERVER['DOCUMENT_ROOT'] . "/$path";
  39. *           }
  40. *
  41. *           return $path;
  42. *       }
  43. *
  44. *       function start_img($attributes) {
  45. *           $this->imageAttributes = $attributes;
  46. *           return '';
  47. *       }
  48. *
  49. *       function end_img($cdata) {
  50. *           $src = $this->truePath($this->imageAttributes['src']);
  51. *           list($w, $h, $t, $whs) = getimagesize($src);
  52. *
  53. *           $this->imageAttributes['height'] = $w;
  54. *           $this->imageAttributes['width']  = $h;
  55. *
  56. *           return sprintf(
  57. *             '<img %s/>',
  58. *             XML_Transformer::attributesToString($this->imageAttributes)
  59. *           );
  60. *       }
  61. *   }
  62. *   ?>
  63. *
  64. * @author  Sebastian Bergmann <sb@sebastian-bergmann.de>
  65. * @author  Kristian K÷hntopp <kris@koehntopp.de>
  66. * @version $Revision: 1.23 $
  67. * @access  public
  68. */
  69. class XML_Transformer_Namespace {
  70.     // {{{ Members
  71.  
  72.     /**
  73.     * @var    string
  74.     * @access public
  75.     */
  76.     var $defaultNamespacePrefix = '';
  77.  
  78.     /**
  79.     * @var    boolean
  80.     * @access public
  81.     */
  82.     var $secondPassRequired = false;
  83.  
  84.     /**
  85.     * @var    array
  86.     * @access private
  87.     */
  88.     var $_prefix = array();
  89.  
  90.     /**
  91.     * @var    string
  92.     * @access private
  93.     */
  94.     var $_transformer = '';
  95.  
  96.     // }}}
  97.     // {{{ function initObserver($prefix, &$object)
  98.  
  99.     /**
  100.     * Called by XML_Transformer at initialization time.
  101.     * We use this to remember our namespace prefixes
  102.     * (there can be multiple) and a pointer to the
  103.     * Transformer object.
  104.     *
  105.     * @param  string
  106.     * @param  object
  107.     * @access public
  108.     */
  109.     function initObserver($prefix, &$object) {
  110.       $this->_prefix[]    = $prefix;
  111.       $this->_transformer = $object;
  112.     }
  113.  
  114.     // }}}
  115.     // {{{ function startElement($element, $attributes)
  116.  
  117.     /**
  118.     * Wrapper for startElement handler.
  119.     *
  120.     * @param  string
  121.     * @param  array
  122.     * @return string
  123.     * @access public
  124.     */
  125.     function startElement($element, $attributes) {
  126.         $do = 'start_' . $element;
  127.  
  128.         if (method_exists($this, $do)) {
  129.             return $this->$do($attributes);
  130.         }
  131.  
  132.         return sprintf(
  133.           "<%s%s>",
  134.  
  135.           $element,
  136.           XML_Util::attributesToString($attributes)
  137.         );
  138.     }
  139.  
  140.     // }}}
  141.     // {{{ function endElement($element, $cdata)
  142.  
  143.     /**
  144.     * Wrapper for endElement handler.
  145.     *
  146.     * @param  string
  147.     * @param  string
  148.     * @return array
  149.     * @access public
  150.     */
  151.     function endElement($element, $cdata) {
  152.         $do = 'end_' . $element;
  153.  
  154.         if (method_exists($this, $do)) {
  155.             return $this->$do($cdata);
  156.         }
  157.  
  158.         return array(
  159.           sprintf(
  160.             '%s</%s>',
  161.  
  162.             $cdata,
  163.             $element
  164.           ),
  165.           false
  166.         );
  167.     }
  168.  
  169.     // }}}
  170.     // {{{ function function getLock()
  171.  
  172.     /**
  173.     * Lock all other namespace handlers.
  174.     *
  175.     * @return boolean
  176.     * @access public
  177.     * @see    releaseLock()
  178.     */
  179.     function getLock() {
  180.         return $this->_transformer->_callbackRegistry->getLock($this->_prefix[0]);
  181.     }
  182.  
  183.     // }}}
  184.     // {{{ function releaseLock()
  185.  
  186.     /**
  187.     * Releases a lock.
  188.     *
  189.     * @access public
  190.     * @see    getLock()
  191.     */
  192.     function releaseLock() {
  193.         $this->_transformer->_callbackRegistry->releaseLock();
  194.     }
  195.  
  196.     // }}}
  197. }
  198.  
  199. /*
  200.  * vim600:  et sw=2 ts=2 fdm=marker
  201.  * vim<600: et sw=2 ts=2
  202.  */
  203. ?>
  204.